package com.vdongchina.java;

/**
 * 单例与原型的
 */
public class Property implements Cloneable{


    public int num;
    public String name;

    public Property(int num, String name) {
        this.num = num;
        this.name = name;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 原型使用克隆的方式
     * @param args
     * @throws CloneNotSupportedException
     */
    public static void main(String[] args) throws CloneNotSupportedException {

        Property cloneableClass = new Property(1, "test");
        System.out.println(cloneableClass.toString());
        Property cloneableClass1 = (Property) cloneableClass.clone();
        System.out.println(cloneableClass.num == cloneableClass1.num);
        System.out.println(cloneableClass.name == cloneableClass1.name);
        cloneableClass.setName("pig");
        System.out.println(cloneableClass1.getName());
        System.out.println(cloneableClass.getName());
        System.out.println(cloneableClass.name == cloneableClass1.name);
        System.out.println(cloneableClass);
        System.out.println(cloneableClass1);

    }

}
